<?php
/**
 * Created by PhpStorm.
 * User: Zhoujinda
 * Date: 2016/8/8
 * Time: 15:43
 */
namespace Webview\Controller;

use Admin\Api\MemberApi;
use Shop\Api\MemberConfigApi;
use Ucenter\Api\UserGroupApi;
use Ucenter\Api\UserMemberApi;
use Uclient\Api\UserApi;

class VipController extends WebViewController{
    public function index(){
        $this->assignTitle('会员规则');

        $map = ['uid'=>$this->uid];
        $result = apiCall(MemberApi::GET_INFO,[$map]);
        if($result['status']){
            $nickname = $result['info']['nickname'];
            $head  = $result['info']['head'];
            $PICTURE_REMOTE_URL = C('PICTURE_REMOTE_URL');
            if(empty($head)){
                $head = $PICTURE_REMOTE_URL;
            }else{
                if(intval($head)>0){
                    $head = $PICTURE_REMOTE_URL.$head.'&size=120';
                }
            }
        }else{
            exit($result['info']);
        }

        $map = ['uid'=>$this->uid];

        $result = apiCall(UserMemberApi::GET_INFO,[$map]);
        if($result['status']){
            $group_id = $result['info']['group_id'];
        }else{
            exit($result['info']);
        }
        if($group_id==0){
            exit('未知错误');
        }

        $map = ['invite_id'=>$this->uid];

        $result = apiCall(MemberConfigApi::GET_INFO,[$map]);

        if($result['status']){
            $idcode = $result['info']['idcode'];
            $invite_id = $result['info']['invite_id'];
        }else{
            exit($result['info']);
        }

        $invite_count = 0;
        $result = apiCall(MemberConfigApi::COUNT,[$map]);
        if($result['status']){
            $invite_count = $result['info'];
        }else{
            exit($result['info']);
        }
        if(empty($invite_id)){
            //不是邀请注册的用户,需要邀请10个
            if($invite_count<10){
                $tip = "您还需成功邀请注册".(10-$invite_count)."才能成为萌主~";
            }else{
                $tip = '您已经成为萌主~';
            }

        }else{
            //是邀请注册的用户，需要邀请5个
            if($invite_count<5){
                $tip = "您还需成功邀请注册".(5-$invite_count)."才能成为萌主~";
            }else{
                $tip = '您已经成为萌主~';
            }
        }

        $this->assign('nickname',$nickname);
        $this->assign('group_id',$group_id);
        $this->assign('head',$head);
        $this->assign('tip',$tip);

        $this->display();
    }
}